<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="店铺名称">
          <el-input
            v-model="form.shop_name"
            placeholder="请输入店铺名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input
            v-model="form.store_manager_name"
            placeholder="请输入商家负责人"
          ></el-input>
        </el-form-item>
        <el-form-item label="负责人电话">
          <el-input
            v-model="form.store_manager_phone"
            placeholder="请输入商家负责人电话"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="商品分类">
          <el-select
            v-model="form.type"
            placeholder="选择商品类型"
            @change="selectChange"
          >
            <el-option
              v-for="(item, index) in Data"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="时间">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            @change="timeChange"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="ktSum" :model="totalData">
      <span>提成金额：{{ totalData.divide_deductible_amount }}</span>
      <span>运费收入：{{ totalData.seller_sender_amount }}</span>
      <span>订单收入：{{ totalData.seller_order_amount }}</span>
    </div>
    <div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          :index="Method"
          prop="id"
          width="70"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="logo"
          align="center"
          label="商家信息"
          width="300"
        >
          <template slot-scope="scope">
            <div class="modality">
              <el-image
                style="width: 70px; height: 70px"
                :src="imgHeader + scope.row.logo"
                class="leftImg"
              ></el-image>
              <div class="modalityUser">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.company_name"
                  placement="top-start"
                >
                  <span class="text"
                    >公司名称:{{ scope.row.company_name }}</span
                  >
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.seller_shop.shop_name"
                  placement="top-start"
                >
                  <span class="text"
                    >店铺名称:{{ scope.row.seller_shop.shop_name }}</span
                  >
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.seller_type"
                  placement="top-start"
                >
                  <span class="text"
                    >商家类型:{{
                      scope.row.seller_type === 51 ? "主材" : ""
                    }}</span
                  >
                </el-tooltip>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="账户">
          <template slot-scope="scope">
            {{ scope.row.account.seller_name }}
          </template>
        </el-table-column>
        <el-table-column
          prop="store_manager_name"
          align="center"
          label="负责人"
        >
        </el-table-column>
        <el-table-column
          prop="store_manager_phone"
          align="center"
          label="负责人电话"
        >
        </el-table-column>
        <el-table-column prop="date" align="center" label="统计时间">
        </el-table-column>
        <!-- <el-table-column align="center" label="水票图片">
          <template slot-scope="scope">
            <el-image
              style="width: 80px; height: 80px"
              :src="scope.row.water_img"
              fit="cover"
            ></el-image>
          </template>
        </el-table-column> -->
        <el-table-column prop="sale" align="center" label="销售数量">
        </el-table-column>
        <el-table-column
          prop="seller_order_amount"
          align="center"
          label="销售金额"
        >
        </el-table-column>
        <el-table-column
          prop="seller_sender_amount"
          align="center"
          label="运费"
        >
        </el-table-column>
        <el-table-column prop="divide" align="center" label="分成比例">
        </el-table-column>
        <el-table-column
          prop="divide_deductible"
          align="center"
          label="提成扣除金额"
        >
        </el-table-column>
        <el-table-column prop="net_receipts" align="center" label="实收金额">
        </el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button @click="handleGo(scope.row)" size="mini" type="primary"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog
      title="主材商家财务详情"
      :visible.sync="dialogTableVisible"
      width="60%"
    >
      <el-form :inline="true" :model="form2" class="demo-form-inline">
        <el-form-item label="时间">
          <el-date-picker
            v-model="form2.time"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            @change="timeChange2"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div class="zongJi">
        <span>运费收入：{{ freight }}</span>
        <span>订单收入：{{ order }}</span>
      </div>
      <div>
        <el-table
          v-loading="loading2"
          ref="multipleTable"
          :data="formTable"
          border
          style="width: 100%"
        >
          <el-table-column
            label="序号"
            type="index"
            :index="Method2"
            prop="id"
            width="60"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="logo"
            align="center"
            label="商家信息"
            width="260"
          >
            <template slot-scope="scope">
              <div class="modality">
                <el-image
                  style="width: 70px; height: 70px"
                  :src="imgHeader + scope.row.logo"
                  class="leftImg"
                ></el-image>
                <div class="modalityUser">
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="scope.row.seller_shop.shop_name"
                    placement="top-start"
                  >
                    <span class="text"
                      >商家名称:{{ scope.row.seller_shop.shop_name }}</span
                    >
                  </el-tooltip>
                  <!-- <el-tooltip
                    class="item"
                    effect="dark"
                    content=""
                    placement="top-start"
                  >
                    <span class="text">店铺名称:</span>
                  </el-tooltip>
                  <el-tooltip
                    class="item"
                    effect="dark"
                    :content="scope.row.seller_type_text"
                    placement="top-start"
                  >
                    <span class="text"
                      >店铺类型:{{ scope.row.seller_type_text }}</span
                    >
                  </el-tooltip> -->
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="order_id" align="center" label="订单号">
          </el-table-column>
          <el-table-column prop="goods_name" align="center" label="商品名称">
          </el-table-column>
          <el-table-column prop="order_amount" align="center" label="交易金额">
          </el-table-column>
          <el-table-column prop="sender_amount" align="center" label="运费">
          </el-table-column>
          <!-- <el-table-column align="center" label="水票图片">
          <template slot-scope="scope">
            <el-image
              style="width: 80px; height: 80px"
              :src="scope.row.water_img"
              fit="cover"
            ></el-image>
          </template>
        </el-table-column> -->
          <el-table-column prop="ctime" align="center" label="下单时间">
          </el-table-column>
          <!-- <el-table-column prop="nums" align="center" label="销售金额">
          </el-table-column>
          <el-table-column prop="amount" align="center" label="运费">
          </el-table-column>
          <el-table-column prop="ctime" align="center" label="分成比例">
          </el-table-column>
          <el-table-column prop="amount" align="center" label="提成扣除金额">
          </el-table-column>
          <el-table-column prop="ctime" align="center" label="实收金额">
          </el-table-column> -->
          <!-- <el-table-column align="center" label="操作">
            <template slot-scope="scope">
              <el-button @click="handleGo(scope.row)" size="mini" type="primary"
                >详情</el-button
              >
            </template>
          </el-table-column> -->
        </el-table>
        <div class="pageUser">
          <el-pagination
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            :current-page="page2"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total2"
          >
          </el-pagination>
        </div>
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
import {
  shouChuList,
  getMerchantFinance,
  getTotalAmount,
  getFinanceDetail,
} from "../../../../utils/main";
export default {
  data() {
    return {
      freight: "",
      order: "",
      gridData: [],
      dialogTableVisible: false,
      Data: [
        {
          name: "桶装水",
          id: "1",
        },
      ],
      imgHeader: this.Global.imgHeader,

      token: sessionStorage.getItem("token"),
      //请求特效
      loading: false,
      loading2: false,
      //弹窗
      // dialogVisible: false,
      form: {
        company_name: "",
        store_manager_name: "",
        store_manager_phone: "",
        time: "",
      },
      form2: { time: "" },
      formTable: [],
      //发送请求时间参数
      //展示数据
      tableData: [],
      totalData: {},
      totalDetailData: {},
      page: 1,
      limit: 10,
      total: 0,
      limit2: 10,
      total2: 0,
      page2: 1,
      name: "",
      type: "",
      // 列表参数
      id: "",
      id2: "",
      id3: "",
      shop_name: "",
      company_name: "",
      store_manager_name: "",
      store_manager_phone: "",
      seller_type: "51",
      time: "",
      time2: "",
    };
  },
  methods: {
    //日期
    timeChange(e) {
      this.time = this.form.time;
      this.getList();
    },
    timeChange2(e) {
      this.time2 = this.form2.time;
      this.getFinanceDetail();
    },
    //查询
    onSubmit() {
      // console.log(this.form);
      this.shop_name = this.form.shop_name;
      this.store_manager_name = this.form.store_manager_name;
      this.store_manager_phone = this.form.store_manager_phone;
      this.time = this.form.time;
      this.page = 1;
      this.getList();
    },
    // 重置
    onReset() {
      this.form.shop_name = "";
      this.form.store_manager_name = "";
      this.form.store_manager_phone = "";
      this.form.time = "";
      this.shop_name = "";
      this.store_manager_name = "";
      this.store_manager_phone = "";
      this.time = "";
      this.getList();
    },
    //水票分类
    // selectChange() {},
    //分页器
    handleSizeChange(val) {
      this.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    // 弹出层
    handleSizeChange2(val) {
      this.limit2 = val;
      this.getFinanceDetail();
    },
    handleCurrentChange2(val) {
      this.page2 = val;
      this.getFinanceDetail();
    },
    // handleSizeChange1(val) {
    //   this.limit1 = val;
    //   this.packageIndexs();
    // },
    // handleCurrentChange1(val) {
    //   this.page1 = val;
    //   this.packageIndexs();
    // },
    // 序号排序
    Method(index) {
      if (this.token < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },
    Method2(index) {
      if (this.token < this.limit2) {
        return this.total2 - index;
      } else {
        return this.total2 - (this.page2 - 1) * this.limit2 - index;
      }
    },
    // 获取主材商家财务列表
    async getList() {
      this.loading = true;
      let res = await getMerchantFinance(
        this.token,
        this.id,
        this.shop_name,
        this.company_name,
        this.store_manager_name,
        this.store_manager_phone,
        this.seller_type,
        this.time,
        this.page,
        this.limit
      );
      if (res.data.status) {
        this.tableData = res.data.data.data || [];
        this.total = res.data.data.count;
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    // 获取主材商家提成总额
    async getTotalList() {
      this.loading = true;
      let res = await getTotalAmount(
        this.token,
        this.id,
        this.company_name,
        this.store_manager_name,
        this.store_manager_phone,
        this.seller_type,
        this.time
      );
      if (res.data.status) {
        this.totalData = res.data.data || [];
        // this.total = res.data.data.count;
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    // 获取主材商家财务列表详情
    async getFinanceDetail() {
      this.loading2 = true;
      let res = await getFinanceDetail(this.token, this.id2, this.time2);
      if (res.data.status) {
        this.formTable = res.data.data.data || [];
        this.total2 = res.data.data.count;
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          this.loading2 = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading2 = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    async handleGo(row) {
      this.dialogTableVisible = true;
      this.id2 = row.id;
      this.id3 = row.id;
      this.getFinanceDetail();
      await getTotalAmount(
        this.token,
        this.id3,
        this.company_name,
        this.store_manager_name,
        this.store_manager_phone,
        this.seller_type,
        this.time
      ).then((res) => {
        // console.log(res);
        this.totalDetailData = res.data.data || {};
      });
      // console.log("000000", this.commodity);
      this.order = this.totalDetailData.seller_order_amount;
      this.freight = this.totalDetailData.seller_sender_amount;
    },
  },
  // 点击详情的事件
  //   handleGo(row) {
  //     // console.log(row);
  //     this.dialogTableVisible = true;
  //     this.id2 = row.id;
  //     this.id3 = row.id;
  //     this.getFinanceDetail();
  //     this.getTotalList();
  //   },
  //   //关闭弹窗
  //   handleClose(done) {
  //     done();
  //     this.packageCounts();
  //   },
  // },
  mounted() {
    // this.sdhadj();
    this.getList();
    this.getTotalList();
  },
};
</script>

<style scoped>
.modality {
  display: flex;
  width: 100%;
}

.modality .leftImg {
  width: 20%;
}

.modalityUser {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 15px;
  width: 70%;
}

.modalityUser .item {
  display: block;
  text-align: left;
  width: 90%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.zongJi {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.zongJi span {
  margin-left: 20px;
}
.ktSum {
  display: flex;
  justify-content: flex-end;
  font-size: 18px;
  margin-bottom: 10px;
  font-size: 18px;
  color: rgba(249, 100, 34, 1);
}
.ktSum span {
  margin-right: 20px;
}
</style>